package cs2340.spring13.team3.wheresmystuff.support;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.node.NullNode;

/**
 * @author Tim Swihart <email obscured since this file is public>
 * @version 1.0
 * @since 2013-04-04
 * 
 *        This class represents the JSON message format returned by our server
 */
public class JSONMessage {
	@JsonProperty("err")
	private String err;

	@JsonProperty("obj")
	private JsonNode obj;

	public JSONMessage() {
		this.setErr("");
		this.obj = NullNode.getInstance();
	};

	public JSONMessage(JsonNode root) {
		String err = "Unknown Error";
		if (root.get("err") != null) {
			err = root.get("err").asText();
		}
		this.setObj(root.get("obj"));
		this.setErr(err);
	}

	public JSONMessage(String err, String cls, JsonNode obj) {
		this.setErr(err);
		this.setObj(obj);
	}

	public JsonNode getObj() {
		return obj;
	}

	public void setObj(JsonNode obj) {
		this.obj = obj;
	}

	public String getErr() {
		return err;
	}

	public void setErr(String err) {
		this.err = err;
	}
}